//
//  LoginViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2017/10/27.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "LoginViewController.h"
#import "XYSegmentView.h"
#import "VerifyViewController.h"
#import "PasswordViewController.h"
#import "WWebViewController.h"

@interface LoginViewController ()<UIScrollViewDelegate,XYSegmentViewDelegate>

@property (nonatomic,strong) UIScrollView *homeScrollView;
@property (nonatomic,strong) XYSegmentView *titScrollView;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"登录";

    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize: 16.0];
    [rightBtn setTitle:@"注册" forState:UIControlStateNormal];
    //[rightBtn setTitleColor:[UIColor colorWithRed:0 green:0.52 blue:1 alpha:1] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    
    PasswordViewController *pdViewController = [[PasswordViewController alloc]init];
    [self addChildViewController:pdViewController];
    
    VerifyViewController *vyViewController = [[VerifyViewController alloc]init];
    [self addChildViewController:vyViewController];

    [self initScrollViewItem];
}

- (void)rightBtnClick {
    WWebViewController *webVc = [[WWebViewController alloc] init];
    webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhP0c0zbqoqL95WAP3ZQsCor";
    webVc.strTitle = @"注册";
    [self.navigationController pushViewController:webVc animated:YES];
}

// 初始化scrollView上的页面
- (void)initScrollViewItem {
    
    if (XIPHONE) {
        _titScrollView = [[XYSegmentView alloc]initWithFrame:CGRectMake(0, 94, WSCREENH_WIDTH, 44)];
    } else {
        _titScrollView = [[XYSegmentView alloc]initWithFrame:CGRectMake(0, 64, WSCREENH_WIDTH, 44)];
    }
    
    _titScrollView.delegate = self;
    _titScrollView.titleArray = @[@"账号密码登录",@"手机快捷登录"];
    _titScrollView.titleSpacing = 0;
    _titScrollView.labelFont = [UIFont systemFontOfSize:15];
    _titScrollView.bottomLabelTextColor = [UIColor blackColor];
    _titScrollView.topLabelTextColor = [UIColor colorWithRed:0.22 green:0.6 blue:0.9 alpha:1];//选中字体颜色
    _titScrollView.selectedBackgroundColor = [UIColor whiteColor];
    _titScrollView.selectedBgViewCornerRadius = 20;
    _titScrollView.sliderHeight = 3;
    _titScrollView.sliderColor = [UIColor colorWithRed:0.22 green:0.6 blue:0.9 alpha:1];//下划线颜色
    _titScrollView.sliderTopMargin = 3;
    _titScrollView.duration = 0.3;
    
    UILabel *lineLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 43, WSCREENH_WIDTH, 1)];
    lineLb.backgroundColor = [UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1];
    [_titScrollView addSubview:lineLb];
    [self.view addSubview:_titScrollView];
    
    CGFloat tableViewW = WSCREENH_WIDTH;
    CGFloat tableViewH = self.view.height - CGRectGetMaxY(_titScrollView.frame)+72;
    
    _homeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titScrollView.frame), tableViewW, tableViewH)];
    _homeScrollView.delegate = self;
    _homeScrollView.backgroundColor = [UIColor clearColor];
    _homeScrollView.contentSize = CGSizeMake(tableViewW * 2, tableViewH);
    _homeScrollView.pagingEnabled = YES;
    _homeScrollView.bounces = NO;
    [self.view addSubview:_homeScrollView];
    
    NSArray *color = @[[UIColor purpleColor],[UIColor redColor]];
    for (int i = 0; i < self.childViewControllers.count; i++) {
        UIViewController *vc = self.childViewControllers[i];
        vc.view.frame = CGRectMake(i * tableViewW, 0, tableViewW, tableViewH);
        vc.view.backgroundColor = color[i];
        [_homeScrollView addSubview:vc.view];
    }
    _titScrollView.outScrollView = _homeScrollView;
    
}

- (void)buttonClick:(NSInteger)index {
    [_homeScrollView setContentOffset:CGPointMake(self.view.width * index, 0) animated:NO];
}

-(void)dealloc{
    //移除所有通知监控
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"LoginBack" object:nil];
}

- (IBAction)btnBackClick:(UIButton *)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
